package com.ymttest.database.sqlwapper.fastturnover;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.fastturnover.TurnoverApplyDetail;

public class TurnoverApplyDetailWrapper {
	
	SqlManager manager;

	public TurnoverApplyDetailWrapper() {
		manager = new SqlManager("fastturnover");
	}

	@SuppressWarnings("unchecked")
	public TurnoverApplyDetail selectByPrimaryKey(String id) {

		TurnoverApplyDetail turnoverApplyDetail = new TurnoverApplyDetail();
		List<TurnoverApplyDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyDetailMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			turnoverApplyDetail = result.get(0);
		}

		return turnoverApplyDetail;
	}
	
	@SuppressWarnings("unchecked")
	public List<TurnoverApplyDetail> selectByApplyNo(String applyNo) {

		List<TurnoverApplyDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyDetailMapper.selectByApplyNo",
						applyNo);
		manager.commit();

		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TurnoverApplyDetail selectBySellerIdAndApplyNo(Long sellerId, String applyNo) {

		HashMap<String, Object> map = new HashMap<>();
		
		map.put("sellerId", sellerId);
		map.put("applyNo", applyNo);
		
		TurnoverApplyDetail turnoverApplyDetail = new TurnoverApplyDetail();
		List<TurnoverApplyDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyDetailMapper.selectBySellerIdAndApplyNo",
						map);
		manager.commit();

		if (result.size() > 0) {
			turnoverApplyDetail = result.get(0);
		}

		return turnoverApplyDetail;
	}
	
	public int updateToFinishByApplyNo(String applyNo) {
		
		int result = manager
				.update(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyDetailMapper.updateToFinishByApplyNo",
						applyNo);
		
		manager.commit();
		
		return result;
	}
	
	public int updateToInitByApplyNo(String applyNo) {
		
		int result = manager
				.update(
						"com.ymttest.database.mapping.fastturnover.TurnoverApplyDetailMapper.updateToInitByApplyNo",
						applyNo);
		
		manager.commit();
		
		return result;
	}
	
	public static void main(String[] args) {
		
		TurnoverApplyDetailWrapper test = new TurnoverApplyDetailWrapper();
		
		System.out.println(test.selectByApplyNo("FKT2020040300000019").get(0).getApply_detail_no());
	}
}
